package day2001;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Random;

public class blfs {
    public static void main(String[] args) throws Exception {
//        com1();//暴力操作成员变量
        com2();//暴力操作成员方法
    }

    private static void com2() throws Exception {
        Class a = anli.class;
        Method[] b = a.getDeclaredMethods();
        for(Method c:b){
            System.out.println(c.getName());
            Class[] d = c.getParameterTypes();
            System.out.println(Arrays.toString(d));
        }
        Object v = a.newInstance();
        Method g = a.getDeclaredMethod("xin_xi2", int.class, int.class, String.class);
        g.setAccessible(true);
        g.invoke(v,10,20,"30");
    }

    private static void com1() throws Exception {
        Class a = anli.class;
        Field[] b =a.getDeclaredFields();
        Object ob = a.newInstance();

        for(Field c:b){
            c.setAccessible(true);
            if(c.getType().getName()=="int")
                c.set(ob,new Random().nextInt(2000));
            if(c.getType().getName()=="java.lang.String")
                c.set(ob,"qqqq");
            System.out.println(c.get(ob));
        }


    }
}
